#!/usr/bin/env python

import sys,os,unittest,platform
import ctypes,struct,time

def progress():
  p=["-\b","/\b","|\b","\\\b",]
  index=0
  while True:
    yield p[index]
    index = (index+1)%len(p)

BUFF_SIZE=1024
MAX_ERROR_COUNT=3
AAC_MAX_CHANNELS=8
DOWN_CHANNEL=2

class M4aTest(unittest.TestCase):
  def setUp(self):
    pass

  def tearDown(self):
    pass

# TEST 01 ----------------------------------------- #
  def test01_ParseMp4Boxes(self):
    f=open("test.m4a","rb")
    s=f.read(8)
    box_length,t1,t2,t3,t4 = struct.unpack(">L4c",s)
    box_type=t1+t2+t3+t4
    self.assertEqual(box_type, "ftyp")
    sys.stderr.write(" <%s(%s)> "%(box_type,box_length))
    s=f.read(box_length-8)

    s=f.read(8)
    while s:
      box_length,t1,t2,t3,t4 = struct.unpack(">L4c",s)
      box_type=t1+t2+t3+t4
      sys.stderr.write(" <%s(%s)> "%(box_type,box_length))
      s=f.read(box_length-8)
      s=f.read(8)


def runall():
  suites=[]
  suites.append(unittest.TestLoader().loadTestsFromTestCase(M4aTest))

  runner = unittest.TextTestRunner(verbosity=2)

  for s in suites:
    runner.run(s)


if __name__=="__main__":
  current_path = os.path.abspath(os.curdir)
  os.chdir(os.path.dirname(os.path.abspath(__file__)))

  sys.path.insert(0,".."+os.sep)
  runall()
  os.chdir(current_path)




